<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="直播间Id" prop="liveRoomId">
        <el-input
          v-model="queryParams.liveRoomId"
          placeholder="请输入直播间Id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场次" prop="times">
        <el-input
          v-model="queryParams.times"
          placeholder="请输入场次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="阵营Id" prop="track">
        <el-input
          v-model="queryParams.track"
          placeholder="请输入阵营Id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="职业Id" prop="job">
        <el-input
          v-model="queryParams.job"
          placeholder="请输入职业Id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="通知消息id" prop="msgId">
        <el-input
          v-model="queryParams.msgId"
          placeholder="请输入通知消息id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="用户Id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户Id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="礼物Id" prop="giftId">
        <el-input
          v-model="queryParams.giftId"
          placeholder="请输入礼物Id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="礼物名称" prop="giftName">
        <el-input
          v-model="queryParams.giftName"
          placeholder="请输入礼物名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="礼物数量" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入礼物数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="单个礼物金额" prop="oneValue">
        <el-input
          v-model="queryParams.oneValue"
          placeholder="请输入单个礼物金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="礼物总金额" prop="totalValue">
        <el-input
          v-model="queryParams.totalValue"
          placeholder="请输入礼物总金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="单个礼物积分" prop="score">
        <el-input
          v-model="queryParams.score"
          placeholder="请输入单个礼物积分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="礼物总积分" prop="totalScore">
        <el-input
          v-model="queryParams.totalScore"
          placeholder="请输入礼物总积分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="礼物等级" prop="giftLevel">
        <el-input
          v-model="queryParams.giftLevel"
          placeholder="请输入礼物等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="是否本次升级" prop="giftUpgrading">
        <el-input
          v-model="queryParams.giftUpgrading"
          placeholder="请输入是否本次升级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="创建时间" prop="createAt">
        <el-date-picker clearable
          v-model="queryParams.createAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="数据变更时间" prop="updateAt">
        <el-date-picker clearable
          v-model="queryParams.updateAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择数据变更时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['data:giftRecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['data:giftRecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['data:giftRecord:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['data:giftRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="giftRecordList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="id" /> -->
      <el-table-column fixed label="直播间Id" align="center" prop="liveRoomId" />
      <el-table-column fixed label="场次" align="center" prop="times" />
      <el-table-column fixed label="用户Id" align="center" prop="userId" />
      <el-table-column  label="阵营Id" align="center" prop="track" />
      <el-table-column label="职业Id" align="center" prop="job" />
      <!-- <el-table-column label="通知消息id" align="center" prop="msgId" /> -->
      <!-- <el-table-column label="礼物Id" width="150px" align="center" prop="giftId" /> -->
      <el-table-column label="礼物名称" align="center" prop="giftName" />
      <el-table-column label="礼物数量" align="center" prop="amount" />
      <el-table-column label="单个礼物金额" align="center" prop="oneValue" >
         <template slot-scope="scope">
          <span>{{ (scope.row.oneValue/1000).toFixed(2) }}元</span>
        </template>
      </el-table-column>
      <el-table-column label="礼物总金额" width="150px" align="center" prop="totalValue" >
         <template slot-scope="scope">
          <span>{{ (scope.row.totalValue/1000).toFixed(2) }}元</span>
        </template>
      </el-table-column>
      <el-table-column label="单个礼物积分" width="150px" align="center" prop="score" />
      <el-table-column label="礼物总积分" width="150px" align="center" prop="totalScore" />
      <el-table-column label="礼物等级" align="center" prop="giftLevel" />
      <el-table-column label="是否本次升级" align="center" prop="giftUpgrading" />
      <el-table-column label="创建时间" align="center" prop="createAt" width="180">
        <template slot-scope="scope">
          <span>{{ (scope.row.createAt) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据变更时间" align="center" prop="updateAt" width="180">
        <template slot-scope="scope">
          <span>{{ (scope.row.updateAt) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['data:giftRecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['data:giftRecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改礼物记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="直播间Id" prop="liveRoomId">
          <el-input v-model="form.liveRoomId" placeholder="请输入直播间Id" />
        </el-form-item>
        <el-form-item label="场次" prop="times">
          <el-input v-model="form.times" placeholder="请输入场次" />
        </el-form-item>
        <el-form-item label="阵营Id" prop="track">
          <el-input v-model="form.track" placeholder="请输入阵营Id" />
        </el-form-item>
        <el-form-item label="职业Id" prop="job">
          <el-input v-model="form.job" placeholder="请输入职业Id" />
        </el-form-item>
        <el-form-item label="通知消息id" prop="msgId">
          <el-input v-model="form.msgId" placeholder="请输入通知消息id" />
        </el-form-item>
        <el-form-item label="用户Id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户Id" />
        </el-form-item>
        <el-form-item label="礼物Id" prop="giftId">
          <el-input v-model="form.giftId" placeholder="请输入礼物Id" />
        </el-form-item>
        <el-form-item label="礼物名称" prop="giftName">
          <el-input v-model="form.giftName" placeholder="请输入礼物名称" />
        </el-form-item>
        <el-form-item label="礼物数量" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入礼物数量" />
        </el-form-item>
        <el-form-item label="单个礼物金额" prop="oneValue">
          <el-input v-model="form.oneValue" placeholder="请输入单个礼物金额" />
        </el-form-item>
        <el-form-item label="礼物总金额" prop="totalValue">
          <el-input v-model="form.totalValue" placeholder="请输入礼物总金额" />
        </el-form-item>
        <el-form-item label="单个礼物积分" prop="score">
          <el-input v-model="form.score" placeholder="请输入单个礼物积分" />
        </el-form-item>
        <el-form-item label="礼物总积分" prop="totalScore">
          <el-input v-model="form.totalScore" placeholder="请输入礼物总积分" />
        </el-form-item>
        <el-form-item label="礼物等级" prop="giftLevel">
          <el-input v-model="form.giftLevel" placeholder="请输入礼物等级" />
        </el-form-item>
        <el-form-item label="是否本次升级" prop="giftUpgrading">
          <el-input v-model="form.giftUpgrading" placeholder="请输入是否本次升级" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createAt">
          <el-date-picker clearable
            v-model="form.createAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数据变更时间" prop="updateAt">
          <el-date-picker clearable
            v-model="form.updateAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择数据变更时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGiftRecord, getGiftRecord, delGiftRecord, addGiftRecord, updateGiftRecord } from "@/api/data/giftRecord"

export default {
  name: "GiftRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 礼物记录表格数据
      giftRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        liveRoomId: null,
        times: null,
        track: null,
        job: null,
        msgId: null,
        userId: null,
        giftId: null,
        giftName: null,
        amount: null,
        oneValue: null,
        totalValue: null,
        score: null,
        totalScore: null,
        giftLevel: null,
        giftUpgrading: null,
        createAt: null,
        updateAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        liveRoomId: [
          { required: true, message: "直播间Id不能为空", trigger: "blur" }
        ],
        job: [
          { required: true, message: "职业Id不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "用户Id不能为空", trigger: "blur" }
        ],
        giftId: [
          { required: true, message: "礼物Id不能为空", trigger: "blur" }
        ],
        giftName: [
          { required: true, message: "礼物名称不能为空", trigger: "blur" }
        ],
        amount: [
          { required: true, message: "礼物数量不能为空", trigger: "blur" }
        ],
        oneValue: [
          { required: true, message: "单个礼物金额不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询礼物记录列表 */
    getList() {
      this.loading = true
      listGiftRecord(this.queryParams).then(response => {
        this.giftRecordList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        liveRoomId: null,
        times: null,
        track: null,
        job: null,
        msgId: null,
        userId: null,
        giftId: null,
        giftName: null,
        amount: null,
        oneValue: null,
        totalValue: null,
        score: null,
        totalScore: null,
        giftLevel: null,
        giftUpgrading: null,
        createAt: null,
        updateAt: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加礼物记录"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getGiftRecord(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改礼物记录"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGiftRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addGiftRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除礼物记录编号为"' + ids + '"的数据项？').then(function() {
        return delGiftRecord(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('data/giftRecord/export', {
        ...this.queryParams
      }, `giftRecord_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
